package com.hns.can.energy.service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.hns.can.common.aop.orgTree.LeftOrgAnnotation;
import com.hns.can.common.constants.GlobalConst;
import com.hns.can.common.formula.FillCodeDscValue;
import com.hns.can.common.formula.FillParamsVo;
import com.hns.can.common.vo.CommonParamsVo;
import com.hns.can.energy.vo.AbnorEnergyStatisVo;
import com.hns.can.master.entity.CommMftAlmEntity;
import com.hns.frame.mybatis.Pagination;
import com.hns.frame.service.CommonService;
import com.hns.tool.pub.PubUtil;

/**
 * 异常能耗service
 * @author:Fisher
 * @email:zhuangcaijin@126.com
 * @version Revision 2.0.0
 */
@Service
public class ReportAbnorEnergyStatisService extends CommonService {
    
    @Autowired
    private FillCodeDscValue codeDscValue;
    
    /**
     * 异常能耗查询
     * @param vo
     * @return
     * @throws Exception
     * @author:Fisher
     * @email:zhuangcaijin@126.com
     */
    @LeftOrgAnnotation()
    @Transactional
    public Pagination searchReportAbnorEnergyStatis(CommonParamsVo vo) throws Exception {
        Pagination page = this.myBatisPage("reportAbnorEnergy.searchReportAbnorEnergyStatisCount", 
            "reportAbnorEnergy.searchReportAbnorEnergyStatis", vo, AbnorEnergyStatisVo.class);
        
        fillReportAbnorEnergyStatis(page.getData());
        return page;
    }
    
    /**
     * 导出
     * @param vo
     * @return
     * @throws Exception
     * @author:Fisher
     * @email:zhuangcaijin@126.com
     */
    @LeftOrgAnnotation()
    @Transactional
    @SuppressWarnings({"unchecked" })
    public List<AbnorEnergyStatisVo> exportReportAbnorEnergyStatis(CommonParamsVo vo) throws Exception {
        List list = PubUtil.convertListMapToObject(sqlMapDao.selectList("reportAbnorEnergy.searchReportAbnorEnergyStatis", vo), AbnorEnergyStatisVo.class);
        fillReportAbnorEnergyStatis(list);
        return list;
    }

    private void fillReportAbnorEnergyStatis(List list) throws Exception {
        //转化生成线路名称
        Map<String,String> map = new HashMap<String,String>();
        map.put("lineName", GlobalConst.DEFAULT_CACHE_VALUE);
        FillParamsVo fileVo1 = new FillParamsVo("lineId", map);
        
        //转化生成机构名称
        map = new HashMap<String,String>();
        map.put("organName",  GlobalConst.DEFAULT_CACHE_VALUE);
        FillParamsVo fileVo2 = new FillParamsVo("organId", map);
        
        codeDscValue.fillInfoValue(list,new String[] {GlobalConst.CACHE_KEY_BASE_LINE_INFO, 
            GlobalConst.CACHE_KEY_BASE_ORGAN}, fileVo1, fileVo2);
        
        Map<String, String> mapTmp = new HashMap<String, String>();
        mapTmp.put("carType", "CAT00000");
        codeDscValue.fillCodeDscValue(list, mapTmp);
    }
}
